home *** CD-ROM | disk | FTP | other *** search
/ Freelog 121 / FreelogMagazineJuilletAout2014-No121.iso / Outils / Adobe-Air / adobe-air_13.exe / [0] / setup.swf / scripts / components / LocalizedLabel.as < prev    next >
Text File  |  2014-03-27  |  5KB  |  193 lines

  1. package components
  2. {
  3.    import flash.text.Font;
  4.    import mx.controls.Label;
  5.    import mx.events.PropertyChangeEvent;
  6.    import mx.styles.StyleManager;
  7.    
  8.    public class LocalizedLabel extends Label
  9.    {
  10.       
  11.       private static var fontArray:Array = Font.enumerateFonts(false);
  12.        
  13.       
  14.       private var isFontRetrieved:Boolean = false;
  15.       
  16.       private var defaultAppFontFamily:String;
  17.       
  18.       private var _resourceName:String;
  19.       
  20.       private var _resourceParams:Array;
  21.       
  22.       private var _bundleName:String;
  23.       
  24.       private var _useHTML:Boolean = false;
  25.       
  26.       private var cachedEmbeddedFont:Font;
  27.       
  28.       public function LocalizedLabel()
  29.       {
  30.          super();
  31.       }
  32.       
  33.       private function set _143661260resourceParams(param1:Array) : void
  34.       {
  35.          trace(this.id + " set resourceName: " + this.resourceName);
  36.          this._resourceParams = param1;
  37.          invalidateProperties();
  38.       }
  39.       
  40.       [Bindable(event="propertyChange")]
  41.       public function set resourceName(param1:String) : void
  42.       {
  43.          var _loc2_:Object = this.resourceName;
  44.          if(_loc2_ !== param1)
  45.          {
  46.             this._384566343resourceName = param1;
  47.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"resourceName",_loc2_,param1));
  48.          }
  49.       }
  50.       
  51.       override protected function commitProperties() : void
  52.       {
  53.          var _loc1_:String = null;
  54.          if(this.resourceName)
  55.          {
  56.             _loc1_ = this.localizeText();
  57.             if(this.useHTML)
  58.             {
  59.                htmlText = _loc1_;
  60.             }
  61.             else
  62.             {
  63.                text = _loc1_;
  64.             }
  65.          }
  66.          if(this.useHTML)
  67.          {
  68.             this.ensureGlyphs(htmlText);
  69.          }
  70.          else
  71.          {
  72.             this.ensureGlyphs(text);
  73.          }
  74.          super.commitProperties();
  75.       }
  76.       
  77.       private function set _384566343resourceName(param1:String) : void
  78.       {
  79.          this._resourceName = param1;
  80.          invalidateProperties();
  81.       }
  82.       
  83.       private function set _1377046061bundleName(param1:String) : void
  84.       {
  85.          this._bundleName = param1;
  86.          invalidateProperties();
  87.       }
  88.       
  89.       protected function localizeText() : String
  90.       {
  91.          return LocalizationManager.getInstance().getString(this.resourceName,this.bundleName,this.resourceParams);
  92.       }
  93.       
  94.       override public function initialize() : void
  95.       {
  96.          super.initialize();
  97.       }
  98.       
  99.       [Bindable(event="propertyChange")]
  100.       public function set bundleName(param1:String) : void
  101.       {
  102.          var _loc2_:Object = this.bundleName;
  103.          if(_loc2_ !== param1)
  104.          {
  105.             this._1377046061bundleName = param1;
  106.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"bundleName",_loc2_,param1));
  107.          }
  108.       }
  109.       
  110.       [Bindable(event="propertyChange")]
  111.       public function set useHTML(param1:Boolean) : void
  112.       {
  113.          var _loc2_:Object = this.useHTML;
  114.          if(_loc2_ !== param1)
  115.          {
  116.             this._148395598useHTML = param1;
  117.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"useHTML",_loc2_,param1));
  118.          }
  119.       }
  120.       
  121.       protected function ensureGlyphs(param1:String) : void
  122.       {
  123.          var _loc2_:String = null;
  124.          var _loc3_:Font = null;
  125.          if(!this.isFontRetrieved)
  126.          {
  127.             this.isFontRetrieved = true;
  128.             _loc2_ = getStyle("fontFamily");
  129.             if(_loc2_.match(/,/))
  130.             {
  131.                return;
  132.             }
  133.             for each(_loc3_ in fontArray)
  134.             {
  135.                if(_loc3_.fontName == _loc2_)
  136.                {
  137.                   this.cachedEmbeddedFont = _loc3_;
  138.                   this.defaultAppFontFamily = StyleManager.getStyleDeclaration("Application").getStyle("fontFamily");
  139.                }
  140.             }
  141.          }
  142.          if(this.cachedEmbeddedFont)
  143.          {
  144.             if(!this.cachedEmbeddedFont.hasGlyphs(param1))
  145.             {
  146.                setStyle("fontFamily",this.defaultAppFontFamily);
  147.             }
  148.             else
  149.             {
  150.                setStyle("fontFamily",this.cachedEmbeddedFont.fontName);
  151.             }
  152.          }
  153.       }
  154.       
  155.       [Bindable(event="propertyChange")]
  156.       public function set resourceParams(param1:Array) : void
  157.       {
  158.          var _loc2_:Object = this.resourceParams;
  159.          if(_loc2_ !== param1)
  160.          {
  161.             this._143661260resourceParams = param1;
  162.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"resourceParams",_loc2_,param1));
  163.          }
  164.       }
  165.       
  166.       private function set _148395598useHTML(param1:Boolean) : void
  167.       {
  168.          this._useHTML = param1;
  169.          invalidateProperties();
  170.       }
  171.       
  172.       public function get useHTML() : Boolean
  173.       {
  174.          return this._useHTML;
  175.       }
  176.       
  177.       public function get resourceParams() : Array
  178.       {
  179.          return this._resourceParams;
  180.       }
  181.       
  182.       public function get resourceName() : String
  183.       {
  184.          return this._resourceName;
  185.       }
  186.       
  187.       public function get bundleName() : String
  188.       {
  189.          return this._bundleName;
  190.       }
  191.    }
  192. }
  193.